//
//  FCHomeVC.m
//  FundChain
//
//  Created by 肖浩然的mac on 2018/2/26.
//  Copyright © 2018年 RUIXIN. All rights reserved.
//

#import "FCHomeVC.h"
#import "XLSlideMenu.h"
#import "FCCyclePagerViewCell.h"
#import "FCBottomTransactionhistoryCell.h"
#import "FCWalletTransactionDetailVC.h"
#import "FCScanCodeVC.h"
#import "FCSendAndReceiveVC.h"
#import "FCUserModel.h"
#import "FCLoginVC.h"
#import "FCTransactionHistoryVC.h"
#import "PagedFlowView.h"
#import "FCFirstVC.h"
#import "FCBaseNavigationVC.h"
#import "FCSendScanCodeVC.h"
#import "FCMJRefreshFooter.h"
#import "FCMJRefreshHeader.h"
#import "FCCCHStatusModel.h"
@interface FCHomeVC ()<TYCyclePagerViewDelegate,TYCyclePagerViewDataSource,UITableViewDataSource,UITableViewDelegate>{
    UIView     *_viewNav;
    UIImageView *_imageViewDismiss;
    UILabel *_tipsLabel;
    UIView *_bgNetView;
    UIButton *_refreshbtn;
    UIView *_bgTableViewView;
    UIImageView *_bottomImageViewDismiss;
    UILabel *_bottomTipsLabel;
}
/* TYCyclePagerView */
@property (strong, nonatomic) TYCyclePagerView *pagerView;
/* TYPageControl */
@property (strong, nonatomic) TYPageControl *pageControl;;
@property (nonatomic, strong) NSArray *datas;
/* operationImageView */
@property (strong, nonatomic) UIImageView *operationImageView;
/* _tableView */
@property (strong, nonatomic) UITableView *tableView;
/* viewLine */
@property (strong, nonatomic) UIView *viewLine;
/* 钱包余额 */
@property (strong, nonatomic) FCBalanceModel  *balanceModel;
/* 钱包信息 */
@property (strong, nonatomic) FCWalletsModel *walletModel;

/* imageIcon */
@property (strong, nonatomic) NSArray *imageArr;
/* title */
@property (strong, nonatomic) NSArray *titleArr;
/* 标题 */
@property (strong, nonatomic) UILabel *backLabel;

/* 交易记录模型 */
@property (strong, nonatomic) FCTransactionHistoryModel *transactionHistoryModel;
/* 交易详情数据源 */
@property (strong, nonatomic) NSMutableArray *orderArr;

/* 登陆过的所有钱包 */
@property (strong, nonatomic) NSMutableArray *loginAllCoinsArr;

/* 登陆过的所有余额 */
@property (strong, nonatomic) NSMutableArray *loginbalanceArr;

/* FCSendAndReceiveVC */
@property (strong, nonatomic) FCSendAndReceiveVC *sendAndReceiveVC ;

/* walletId */
@property (copy, nonatomic) NSString *walletIdStr;

/** 当前页 */
@property(nonatomic, assign) NSUInteger currentPage;

/* 交易记录 */
@property (strong, nonatomic) FCTransactionHistoryDetailModel * transactionHistoryDetailModel;
/* topview */
@property (strong, nonatomic) UIView *topView;

/* 左边添加或者删除货币 */
@property (assign, nonatomic) BOOL isLeftAddCoins;

/* 自定义背景 */
@property (strong, nonatomic) UIView *bgView;

/* 记录左边更改等值货币的 */
@property (strong, nonatomic) FCCurrentResultModel *currentResultModel;

/* 左侧通知 */
@property (assign, nonatomic) BOOL leftNotic;


/* <#Annotation#> */
@property (strong, nonatomic) FCWalletsModel *walletModel1;
@property (strong, nonatomic) FCWalletsModel *walletModel2;
@property (strong, nonatomic) FCWalletsModel *walletModel3;
@property (strong, nonatomic) FCWalletsModel *walletModel4;
@property (strong, nonatomic) FCWalletsModel *walletModel5;

/* <#Annotation#> */
@property (strong, nonatomic) NSMutableArray *deleteCoinsArr;
@property (strong, nonatomic) FCWalletsModel *walletModelD1;
@property (strong, nonatomic) FCWalletsModel *walletModelD2;
@property (strong, nonatomic) FCWalletsModel *walletModelD3;
@property (strong, nonatomic) FCWalletsModel *walletModelD4;
@property (strong, nonatomic) FCWalletsModel *walletModelD5;

@property (copy, nonatomic) NSString *cchStatus;
@end

@implementation FCHomeVC

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [FCLocalUserHelper saveIsMainVC:@"1"];
  
    FCCCHStatusModel *model = [FCLocalUserHelper getCCHstatusModel];
    self.cchStatus = model.statusStr;
     [self loadUserInfoData];
}
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    
    
    //self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    [FCLocalUserHelper saveIsMainVC:@"1"];
   
    //左边点击不同货币的通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(leftChangeWalletId:) name:@"leftChangeWalletId" object:nil];
    //左边钱包货币的通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(leftChangeReloadWallet) name:@"leftChangeReloadWallet" object:nil];
    //接收左边点击不同等值货币更改的通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeDifferentEquivalentCoins:) name:@"changeDifferentEquivalentCoins" object:nil];

   
    [self addImageArr];
    [self addTitleArr];
    [self setNav];
    [self setupUI];
    [self refresh];
    [self addDismissImage];
    [self NetWorkStatus];
    [self addNetWorkStatusView];
}
-(void)addDismissImage{
    
    UIView *bgTableViewView = [UIView new];
    _bgTableViewView = bgTableViewView;
    [self.view addSubview:bgTableViewView];
    [bgTableViewView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.viewLine.mas_bottom);
        make.left.mas_offset(0);
        make.right.mas_offset(0);
        make.bottom.mas_offset(0);
    }];
    bgTableViewView.backgroundColor = kClearColor;
    bgTableViewView.hidden =YES;
    //图片
    _bottomImageViewDismiss =[UIImageView new];
    [bgTableViewView addSubview:_bottomImageViewDismiss];
    [_bottomImageViewDismiss mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(50*KScreenHeightScale1334);
        make.centerX.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(160, 160));
    }];
    [_bottomImageViewDismiss setBackgroundColor:[UIColor clearColor]];
    [_bottomImageViewDismiss setImage:[UIImage imageNamed:@"img_data"]];
    if (SCREEN_WIDTH == 320) {
        [_bottomImageViewDismiss mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(80, 80));
        }];
    }
    //提示
    UILabel *bottomTipsLabel = [UILabel new];
    _bottomTipsLabel = bottomTipsLabel;
    [bgTableViewView addSubview:bottomTipsLabel];
    [bottomTipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_bottomImageViewDismiss.mas_bottom).offset(10);
        make.centerX.mas_equalTo(0);
    }];
    bottomTipsLabel.textColor = kGrayColor;
    bottomTipsLabel.text = Localized(@"还没有数据");
    
    //刷新
    UIButton *refreshbtn = [UIButton new];
    _refreshbtn = refreshbtn;
    [bgTableViewView addSubview:refreshbtn];
    [refreshbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_bottomImageViewDismiss.mas_bottom).offset(10);
        make.centerX.mas_equalTo(0);
    }];
    [refreshbtn setTitle:Localized(@"刷新") forState:UIControlStateNormal];
    [refreshbtn setTitleColor:kGrayColor forState:UIControlStateNormal];
    [refreshbtn addTarget:self action:@selector(refreshbtnClick) forControlEvents:UIControlEventTouchUpInside];
    refreshbtn.hidden = YES;
    
    
}
-(void)NetWorkStatus{
    
    [FCLocalUserHelper hasNetwork:^(bool has) {
        if (has)
        {

        } else
        {
        _bgNetView.hidden = NO;
        [self.tableView bringSubviewToFront:_bgNetView];
        }
    }];
}
-(void)refreshbtnClick{
    [self refresh];
}
-(void)addNetWorkStatusView{

    UIView *bgView = [UIView new];
    _bgNetView = bgView;
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(64);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    bgView.backgroundColor = kWhiteColor;
    bgView.hidden =YES;
    _imageViewDismiss =[UIImageView new];
    [bgView addSubview:_imageViewDismiss];
    [_imageViewDismiss mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(114*KScreenHeightScale1334);
        make.centerX.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(160, 160));
    }];
    [_imageViewDismiss setBackgroundColor:[UIColor clearColor]];
    [_imageViewDismiss setImage:[UIImage imageNamed:@"img_network"]];
    
    //提示
    UILabel *tipsLabel = [UILabel new];
    _tipsLabel = tipsLabel;
    [bgView addSubview:tipsLabel];
    [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_imageViewDismiss.mas_bottom).offset(50);;
        make.centerX.mas_equalTo(0);
    }];
    tipsLabel.textColor = kGrayColor;
    tipsLabel.text = Localized(@"网络连接失败");
    //btn
    UIButton *btn = [UIButton new];
    [bgView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(tipsLabel.mas_bottom).offset(10);
        make.centerX.mas_equalTo(0);
    }];
    [btn setTitle:Localized(@"刷新") forState:UIControlStateNormal];
    [btn setTitleColor:kRedOrangeColor forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(refreshClick) forControlEvents:UIControlEventTouchUpInside];
    
    
}
-(void)refreshClick{
    [FCLocalUserHelper pushMainTabbarController];
}
#pragma mark-接收左侧改变货币的通知
-(void)leftChangeWalletId:(NSNotification*)notic{
    
    NSLog(@"左侧改变货币的通知%@",notic.userInfo[@"walletId"]);
    [self postAllWalletAddressWith:notic.userInfo[@"walletId"]];
    //    [self postTransactionHistoryMessageWith:notic.userInfo[@"walletId"]];
    
    
    NSArray *arr = self.coinsArr;
    NSLog(@"钱包个数:%zd",arr.count);
    
    
    
    self.walletIdStr = notic.userInfo[@"walletId"];
        [self postTransactionHistoryMessageWith:notic.userInfo[@"walletId"]];
    NSString *index = notic.userInfo[@"index"];
//    self.backLabel
    switch ([notic.userInfo[@"walletId"] integerValue]) {
        case 1001:
        {
            self.backLabel.text = Localized(@"比特币");
        }
            break;
        case 1005:
        {
            self.backLabel.text = Localized(@"莱特币");
        }
            break;
        case 1006:
        {
            self.backLabel.text = Localized(@"比特币现金");
        }
            break;
        case 1009:
        {
            self.backLabel.text = Localized(@"加密现金币");
        }
            break;
        case 1010:
        {
            self.backLabel.text = Localized(@"零币");
        }
            break;
            
        default:
            break;
    }
    
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        
        [_pagerView scrollToItemAtIndex:[index integerValue] animate:YES];
        [self.pageControl setCurrentPage:[index integerValue]];
        
    });

}
-(void)leftChangeReloadWallet{
    self.isLeftAddCoins = YES;
    [self getAllCoinsMessage];

}
//接收左边点击不同等值货币更改的通知
-(void)changeDifferentEquivalentCoins:(NSNotification*)notic{
    
    NSLog(@"模型是:%@",notic.object);
    self.leftNotic = YES;
    self.currentResultModel = notic.object;
    
    
}
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
-(void)addImageArr{
    
    self.imageArr = @[@"btc_50pt",@"ltc_50pt",@"bch_50pt",@"cch_50pt",@"zec_50pt"];
}
-(void)addTitleArr{
    
    self.titleArr = @[Localized(@"比特币 "),Localized(@"莱特币 "),Localized(@"比特币现金 "),Localized(@"加密现金币 "),Localized(@"零币 ")];
    
    
    
}
#pragma mark-leftItem
-(void)leftBtnClick{
    [self.xl_sldeMenu showLeftViewControllerAnimated:true];
    
}
#pragma mark-rightItem
-(void)rightBtnClick{
    NSString *walletId;
    if (self.walletIdStr == nil) {
        walletId = @"1009";
    }else{
        walletId = self.walletIdStr;
    }
    FCCurrentResultModel *currentResultModel;
    if (self.leftNotic) {
        currentResultModel = self.currentResultModel;
    }else{
        currentResultModel = [FCLocalUserHelper getFMDBCurrentResultModel:walletId];
    }
    FCScanCodeVC *vc = [FCScanCodeVC new];
    vc.walletId = walletId;
    vc.currentResultModel = currentResultModel;
    [self.navigationController pushViewController:vc animated:YES];
    
}
#pragma mark-设置导航栏
-(void)setNav{
    self.navigationController.navigationBarHidden = YES;
    _viewNav =[UIView new];
    [self.view addSubview:_viewNav];
    [_viewNav mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            if (iPhoneX) {
                
                make.left.right.top.mas_equalTo(self.view.safeAreaInsets);
                make.height.mas_equalTo(88);
            }else{
                make.left.right.mas_equalTo(0);
                make.height.mas_equalTo(64);
                make.top.mas_equalTo(0);
            }
        }else{
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(64);
            make.top.mas_equalTo(0);
        }
        
    }];
    _viewNav.backgroundColor = kRedOrangeColor;
    
    UIButton *leftBtn = [UIButton new];
    [self.view addSubview:leftBtn];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15*KScreenWidthScale750);
        make.centerY.mas_equalTo(_viewNav.mas_centerY).offset(8);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    [leftBtn setImage:[UIImage imageNamed:@"icon_menu"]  forState:UIControlStateNormal];
    [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    //返回
    UILabel *backLabel = [UILabel new];
    self.backLabel = backLabel;
    [_viewNav addSubview:backLabel];
    [backLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_viewNav);
        make.centerY.mas_equalTo(_viewNav.mas_centerY).offset(8);
    }];
    backLabel.textColor = [UIColor whiteColor];
    backLabel.font = KOverstrikingfont(36);
    //右bar
    UIButton *rightBtn = [UIButton new];
    [_viewNav addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15*KScreenWidthScale750);
        make.centerY.mas_equalTo(_viewNav.mas_centerY).offset(8);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    [rightBtn setImage:[UIImage imageNamed:@"icon_scan"] forState:UIControlStateNormal];
    //事件
    [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
}
-(void)setupUI{
    
    
    self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.bgView.backgroundColor = HEXACOLOR(0x000000, 0.7);
    if([FCLocalUserHelper getLoginState]){
        [self showChrysanthemumAlert:nil];
        
        [[UIApplication sharedApplication].delegate.window addSubview:self.bgView];
    }
    self.bgView.hidden = YES;
    
    
    //上部View
    UIView *topView = [UIView new];
    self.topView = topView;
    [self.view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_viewNav.mas_bottom);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(524*KScreenHeightScale1334);
    }];
    topView.backgroundColor = kRedOrangeColor;
    
    //添加TYCyclePagerView
    [self loadData];
    [self addPagerView];
    [self addPageControl];
    [self addOperationView];
    [self addBottomTableView];
    
}


#pragma mark-添加TYCyclePagerView
- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    _pagerView.frame = CGRectMake(0, 64, CGRectGetWidth(self.view.frame), 200);
    _pageControl.frame = CGRectMake(0, CGRectGetHeight(_pagerView.frame) - 16, CGRectGetWidth(_pagerView.frame), 26);
}
- (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
    TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
    layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame)*0.8, CGRectGetHeight(pageView.frame)*0.8);
    layout.itemSpacing = 15;
    layout.isInfiniteLoop = false;
    //layout.minimumAlpha = 0.3;
    layout.itemHorizontalCenter = YES;
    return layout;
}
-(void)addPagerView{
    
    TYCyclePagerView *pagerView = [[TYCyclePagerView alloc]init];
    //    pagerView.layer.borderWidth = 1;
    pagerView.autoScrollInterval = 0.0;
    pagerView.isInfiniteLoop = NO;
    pagerView.dataSource = self;
    pagerView.delegate = self;
    // registerClass or registerNib
    [pagerView registerClass:[FCCyclePagerViewCell class] forCellWithReuseIdentifier:@"cellId"];
    [self.view addSubview:pagerView];
    _pagerView = pagerView;
}
#pragma mark-添加UIPageControl
-(void)addPageControl{
    TYPageControl *pageControl = [[TYPageControl alloc]init];
    //pageControl.numberOfPages = _datas.count;
    pageControl.currentPageIndicatorSize = CGSizeMake(8, 8);
    //    pageControl.pageIndicatorImage = [UIImage imageNamed:@"Dot"];
    //    pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"DotSelected"];
    //    pageControl.contentInset = UIEdgeInsetsMake(0, 20, 0, 20);
    //    pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    //    pageControl.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    //    [pageControl addTarget:self action:@selector(pageControlValueChangeAction:) forControlEvents:UIControlEventValueChanged];
    
    [_pagerView addSubview:pageControl];
    self.pageControl = pageControl;
    
}
- (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
    NSLog(@"Scrolled to page # %ld", (long)index);
    self.pageControl.currentPage = toIndex;
    FCWalletsModel *model = self.coinsArr[toIndex];
    NSLog(@"下标walletId:%@",model.walletId);
    self.walletIdStr = model.walletId;
    [self postTransactionHistoryMessageWith:model.walletId];
    [self postAllWalletAddressWith:model.walletId];
    
    if (self.orderArr > 0) {
        [self.orderArr removeAllObjects];
    }
    [self.tableView.mj_header beginRefreshing];
    [FCLocalUserHelper saveDidScroll:model.walletId];
    switch ([self.walletIdStr integerValue]) {
        case 1001:
        {
            self.backLabel.text = Localized(@"比特币");
        }
            break;
        case 1005:
        {
            self.backLabel.text = Localized(@"莱特币");
        }
            break;
        case 1006:
        {
            self.backLabel.text = Localized(@"比特币现金");
        }
            break;
        case 1009:
        {
            self.backLabel.text = Localized(@"加密现金币");
        }
            break;
        case 1010:
        {
            self.backLabel.text = Localized(@"零币");
        }
            break;
            
        default:
            break;
    }
    
    
    
   
}
//返回显示View的个数
- (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
    return self.coinsArr.count;
}


//返回给某列使用的View
- (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index{
    FCCyclePagerViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndex:index];

    FCWalletsModel *model = self.coinsArr[index];
    NSLog(@"移动:%zd",index);
    NSString *nameStr;
    switch ([model.walletId integerValue]) {
        case 1001:
            {
                nameStr = Localized(@"比特币");
            }
            break;
        case 1005:
        {
            nameStr = Localized(@"莱特币");
        }
            break;
        case 1006:
        {
            nameStr = Localized(@"比特币现金");
        }
            break;
        case 1009:
        {
            nameStr = Localized(@"加密现金币");
        }
            break;
        case 1010:
        {
            nameStr = Localized(@"零币");
        }
            break;
            
        default:
            break;
    }
    cell.moneyLabel.text = [NSString stringWithFormat:@"%@",nameStr];
    cell.moneyImageView.image = [UIImage imageNamed:model.iconImage];
    //移除货币种类
    cell.deleteBtn.tag =[model.walletId integerValue];
    NSLog(@"按钮tage:%zd====钱包id:%@",cell.deleteBtn.tag,model.walletId);
    [cell.deleteBtn addTarget:self action:@selector(deleteCoinsClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //移除货币种类
    if (self.balanceArr.count == self.coinsArr.count) {
        
   
    FCBalanceModel *balanceModel = self.balanceArr[index];
    NSArray *arr = balanceModel.currentResult;
    [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        FCCurrentResultModel *model = [FCCurrentResultModel mj_objectWithKeyValues:obj];
        if ([model.currentId isEqualToString:@"8001"]) {
            
            cell.muchMoneyLabel.text = model.amt;
            
        }
        
    }];
        NSString *nameStr;
        if ([model.walletId isEqualToString:@"1001"]) {
            nameStr = @"BTC";
        }else if ([model.walletId isEqualToString:@"1009"]){
            nameStr = @"CCH";
        }else if ([model.walletId isEqualToString:@"1006"]){
            nameStr = @"BCH";
        }else if ([model.walletId isEqualToString:@"1005"]){
            nameStr = @"LTC";
        }else if ([model.walletId isEqualToString:@"1010"]){
            nameStr = @"ZEC";
        }
        
        cell.equivalentCountLabel.text = [NSString stringWithFormat:@"%@ %@",balanceModel.balance,nameStr];
        
        
        if ([model.walletId isEqualToString:@"1009"]) {
            cell.equivalentCountLabel.hidden = YES;
            cell.equivalentLabel.hidden = YES;
            cell.muchMoneyLabel.text = [NSString stringWithFormat:@"%@",balanceModel.balance];
            cell.muchMoneyTypeLabel.text = @"CCH";
        }else{
            cell.equivalentCountLabel.hidden = NO;
            cell.equivalentLabel.hidden = NO;
            cell.muchMoneyTypeLabel.text = @"USD";
        }
    
    FCCurrentResultModel *currentResultModel;
    if (self.leftNotic) {
        currentResultModel = self.currentResultModel;
    }else{
        currentResultModel = [FCLocalUserHelper getFMDBCurrentResultModel:model.walletId];
    }
    
    FCExchangeRatesModel *rateModel = [FCLocalUserHelper getFMDBExchangeRatesModel:model.walletId ];
    
    if (rateModel) {
        
        
        [self.balanceArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            FCBalanceModel *balanceModel = obj;
            
            if ([model.walletId isEqualToString:balanceModel.walletId]) {
                
                if ([currentResultModel.walletId isEqualToString:model.walletId]) {
                    float result = [currentResultModel.price floatValue]*[balanceModel.balance.trimWhitespace floatValue];
                    
                    cell.muchMoneyLabel.text = [NSString stringWithFormat:@"%.2f",result];
                    cell.muchMoneyTypeLabel.text = currentResultModel.currentName;
                    cell.equivalentCountLabel.text = [NSString stringWithFormat:@"%@ %@",balanceModel.balance,nameStr];
                }
                
            }
        }];
    }
    }
 
    return cell;
}

#pragma mark-操作View(发送和接收的白色View)
-(void)addOperationView{
    
    //背景image
    UIImageView *operationImageView = [UIImageView new];
    self.operationImageView = operationImageView;
    operationImageView.userInteractionEnabled = YES;
    [self.view insertSubview:operationImageView atIndex:99];
    [operationImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.pageControl.mas_bottom).offset(10*KScreenHeightScale1334);
        make.centerX.mas_equalTo(0);
    }];
    operationImageView.image = [UIImage imageNamed:@"bg_wallet_btns"];
    if (SCREEN_WIDTH == 320) {
        [operationImageView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.pageControl.mas_bottom).offset(-10);
            make.centerX.mas_equalTo(0);
        }];
    }
    
    JMBaseButtonConfig *buttonConfig = [JMBaseButtonConfig buttonConfig];
    buttonConfig.title = Localized(@"发送");
    buttonConfig.titleFont = Kfont(36);
    buttonConfig.titleColor = kwarningColor;
    buttonConfig.image = [UIImage imageNamed:@"Send"];
    buttonConfig.styleType = JMButtonStyleTypeTop;
    JMButton *sendBtn = [[JMButton alloc] initWithFrame:CGRectMake(10, 10, 624/2/2-20, 114*KScreenHeightScale1334) ButtonConfig:buttonConfig];
    [sendBtn addTarget:self action:@selector(sendBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [operationImageView addSubview:sendBtn];
    //分割线
    UIView *viewLine =[UIView new];
    [operationImageView addSubview:viewLine];
    [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(30*KScreenHeightScale1334);
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(100*KScreenHeightScale1334);
    }];
    viewLine.backgroundColor =kLineColor;
    
    
    JMBaseButtonConfig *buttonConfig1 = [JMBaseButtonConfig buttonConfig];
    buttonConfig1.title = Localized(@"接收");
    buttonConfig1.titleFont = Kfont(36);
    buttonConfig1.titleColor = kgreenassistColor;
    buttonConfig1.image = [UIImage imageNamed:@"receive"];
    buttonConfig1.styleType = JMButtonStyleTypeTop;
    JMButton *receiveBtn = [[JMButton alloc] initWithFrame:CGRectMake(624/2/2+10, 10, 624/2/2-20, 114*KScreenHeightScale1334) ButtonConfig:buttonConfig1];
    [receiveBtn addTarget:self action:@selector(receiveBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [operationImageView addSubview:receiveBtn];
    
    //事件
    [sendBtn addTarget:self action:@selector(sendBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [receiveBtn addTarget:self action:@selector(receiveBtnClick) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark-send界面
-(void)sendBtnClick{
    
    NSString *walletId;
    if (self.walletIdStr == nil) {
        walletId = @"1009";
    }else{
        walletId = self.walletIdStr;
    }
    FCCurrentResultModel *currentResultModel;
    if (self.leftNotic) {
        currentResultModel = self.currentResultModel;
    }else{
        currentResultModel = [FCLocalUserHelper getFMDBCurrentResultModel:walletId];
    }
    NSLog(@"点击时的walletId:%@",walletId);
    self.sendAndReceiveVC = [FCSendAndReceiveVC new];
    self.sendAndReceiveVC.selectIndex = 0;
    self.sendAndReceiveVC.walletId = walletId;
    self.sendAndReceiveVC.currentResultModel = currentResultModel;
    [self.navigationController pushViewController:self.sendAndReceiveVC animated:YES];
}
-(void)receiveBtnClick{
    NSString *walletId;
    if (self.walletIdStr == nil) {
        walletId = @"1009";
    }else{
        walletId = self.walletIdStr;
    }
    FCCurrentResultModel *currentResultModel;
    if (self.leftNotic) {
        currentResultModel = self.currentResultModel;
    }else{
        currentResultModel = [FCLocalUserHelper getFMDBCurrentResultModel:walletId];
    }
    self.sendAndReceiveVC = [FCSendAndReceiveVC new];
    self.sendAndReceiveVC.selectIndex = 1;
    self.sendAndReceiveVC.walletId = walletId;
    self.sendAndReceiveVC.currentResultModel = currentResultModel;
    [self.navigationController pushViewController:self.sendAndReceiveVC animated:YES];
    
}
#pragma mark-进入钱包交易历史详情页
-(void)viewBtnClick{
    
    NSString *walletId;
    if (self.walletIdStr == nil) {
        walletId = @"1009";
    }else{
        walletId = self.walletIdStr;
    }
    FCCurrentResultModel *currentResultModel;
    if (self.leftNotic) {
        currentResultModel = self.currentResultModel;
    }else{
        currentResultModel = [FCLocalUserHelper getFMDBCurrentResultModel:walletId];
    }
    FCWalletTransactionDetailVC *vc = [FCWalletTransactionDetailVC new];
    vc.walletId = walletId;
    vc.currentResultModel = currentResultModel;
    [self.navigationController pushViewController:vc animated:YES];
    
}
#pragma mark-addBottomTableView
-(void)addBottomTableView{
    //bottomTitle
    UIView *bottomTitleView = [UIView new];
    [self.view addSubview:bottomTitleView];
    [bottomTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.operationImageView.mas_bottom).offset(20*KScreenHeightScale1334);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(100*KScreenHeightScale1334);
    }];
    bottomTitleView.backgroundColor = kWhiteColor;
    //title
    UILabel *titleLabel = [UILabel new];
    [bottomTitleView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*KScreenWidthScale750);
        make.centerY.mas_equalTo(0);
    }];
    titleLabel.text = Localized(@"交易历史");
    titleLabel.font = Kfont(32);
    //进入钱包记录详情页
    UIButton *viewBtn = [UIButton new];
    [bottomTitleView addSubview:viewBtn];
    [viewBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30*KScreenWidthScale750);
        make.centerY.mas_equalTo(0);
    }];
    [viewBtn setBackgroundImage:[UIImage imageNamed:@"icon_next"] forState:UIControlStateNormal];
    //viewLabel
    UILabel *viewLabel = [UILabel new];
    [bottomTitleView addSubview:viewLabel];
    [viewLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(viewBtn.mas_left).offset(-8*KScreenWidthScale750);
        make.centerY.mas_equalTo(0);
    }];
    viewLabel.text = Localized(@"显示所有");
    viewLabel.font = Kfont(28);
    viewLabel.textColor = kGrayColor;
    
    UIButton *viewBtn1 = [UIButton new];
    [bottomTitleView addSubview:viewBtn1];
    [viewBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30*KScreenWidthScale750);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(150/2);
    }];
    [viewBtn1 setBackgroundColor:[UIColor clearColor]];
    //分割线
    UIView *viewLine =[UIView new];
    self.viewLine = viewLine;
    [self.view addSubview:viewLine];
    [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(bottomTitleView.mas_bottom);
        make.height.mas_equalTo(1);
    }];
    viewLine.backgroundColor =kLineColor;
    
    //事件
    [viewBtn1 addTarget:self action:@selector(viewBtnClick) forControlEvents:UIControlEventTouchUpInside];
    //添加tableView
    [self tableView];
    
}
#pragma mark-UItableViewdelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"index%zd",indexPath.row);
    FCTransactionHistoryDetailModel *detailModel = self.orderArr[indexPath.row];
    FCCurrentResultModel *currentResultModel;
    if (self.leftNotic) {
        currentResultModel = self.currentResultModel;
    }else{
        currentResultModel = [FCLocalUserHelper getFMDBCurrentResultModel:self.walletIdStr];
    }
    FCTransactionHistoryVC *vc = [FCTransactionHistoryVC new];
    vc.transactionHistoryDetailModel = detailModel;
    vc.currentResultModel = currentResultModel;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

#pragma mark-UItableViewdatasouce
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 160*KScreenHeightScale1334;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.orderArr.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FCBottomTransactionhistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:@"bottomCell"];
    cell = [[FCBottomTransactionhistoryCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"bottomCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
  
    if (self.orderArr.count>0) {
        _transactionHistoryDetailModel= self.orderArr[indexPath.row];
        cell.transactionHistoryDetailModel = _transactionHistoryDetailModel;
        
        FCTransactionHistoryDetailModel *model = self.orderArr[0];
    NSRange range =NSMakeRange(0, 10);
    NSString * aString = [FCLocalUserHelper getBabyDetailAge:model.sendTime];
    NSString * string = [aString substringWithRange:range];
    NSMutableArray * muArray=[[NSMutableArray    alloc]initWithCapacity:0];
        
    NSString * str ;
    for (int i = 0 ;i<self.orderArr.count;i++) {
        
        FCTransactionHistoryDetailModel *model1 = self.orderArr[i];
        NSString * bString = [FCLocalUserHelper getBabyDetailAge:model1.sendTime];
        str = [bString substringWithRange:range];
        
        if (![string isEqualToString:str]) {
            model1.sameTime = @"1";
            [muArray addObject:self.orderArr[i]];
            string = str;
        }
    }
        
      
        if ([_transactionHistoryDetailModel.sameTime isEqualToString:@"1"]) {
            cell.monthLabel.hidden = NO;
        }else if(indexPath.row == 0){
             cell.monthLabel.hidden = NO;
        }else{
            cell.monthLabel.hidden = YES;
        }
     
    }
    
    
    
    return cell;
}
-(NSMutableArray *)getArrayFormArray:(NSArray*)arr
{
    NSRange range =NSMakeRange(0, 10);
    NSString * aString = arr[0][@"time"];
    NSString * string = [aString substringWithRange:range];
    NSMutableArray * muArray=[[NSMutableArray    alloc]initWithCapacity:0];
    NSString * str ;
    for (int i = 0 ;i<arr.count;i++) {
        NSString * bString = arr[i][@"time"];
        str = [bString substringWithRange:range];
        if (![string isEqualToString:str]) {
            [muArray addObject:arr[i]];
            string = str;
        }
    }
    return muArray;
}
#pragma mark-tableView
//懒加载tableView
-(UITableView*)tableView{
    
    if(!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView ];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.viewLine.mas_bottom);
            make.left.mas_offset(0);
            make.right.mas_offset(0);
            make.bottom.mas_offset(0);
        }];
        _tableView.showsHorizontalScrollIndicator = YES;
        _tableView.backgroundColor = kWhiteColor;
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
        //        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}

- (void)loadData {
    
   [self getAllCoinsMessageForLogin];
    
    
}

-(void)reloadDatd{
    NSArray *datas = self.coinsArr;
    _datas = [datas copy];
    _pageControl.numberOfPages = _datas.count;
    [_pagerView reloadData];
    
    
}



#pragma mark-移除货币种类
-(void)deleteCoinsClick:(UIButton*)send{
    
    NSString *coinsNameStr;
    switch (send.tag) {
        case 1001:
        {
            coinsNameStr = Localized(@"比特币");
        }
            break;
        case 1005:
        {
            coinsNameStr = Localized(@"莱特币");
        }
            break;
        case 1006:
        {
            coinsNameStr = Localized(@"比特币现金");
        }
            break;
        case 1009:
        {
            coinsNameStr = Localized(@"加密现金币");
        }
            break;
        case 1010:
        {
            coinsNameStr = Localized(@"零币");
        }
            break;
            
        default:
            break;
    }
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"%@ %@?",Localized(@"移除"),coinsNameStr] message:[NSString stringWithFormat:Localized(@"此操作将从您的钱包中移除货币。但仍可以重新添加货币并恢复货币。")] preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:Localized(@"是") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self deleteCoins:send.tag];
        
        
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:Localized(@"否") style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
    
    
}
-(void)deleteCoins:(NSInteger)walletId{
    
        // 删除货币
        if (self.coinsArr.count <2) {
            [self showAlert:Localized(@"至少选择一个货币")];
            return;
        }

    [self showChrysanthemumAlert:nil];
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    NSArray *signArr = [FCLocalUserHelper getTimeAndSign];
    NSString *signStr = [NSString stringWithFormat:@"%@",signArr[1]];
    NSString *timeStr = [NSString stringWithFormat:@"%@",signArr[0]];
    [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
    [dict setObject:timeStr forKey:@"time"];
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    [dict setObject:[NSString stringWithFormat:@"%zd",walletId] forKey:@"walletId"];
    NSString *url = Remove_wallet_type_URL;
    
    NSLog(@"walletId:%@",[NSString stringWithFormat:@"%zd",walletId]);
    
    __weak __typeof(self)wself = self;
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        
        if (responseObject) {
            NSLog(@"%@",responseObject);
            if ([responseObject[@"code"] integerValue] == 200) {
                [self hideProgress];
                //获取所有钱包信息
                
                //发送移除的通知
                
                [[NSNotificationCenter defaultCenter]postNotificationName:@"removeCoins" object:nil];
                [self showAlert:Localized(@"移除钱包成功")]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
                
                [wself getAllCoinsMessage];
                });
                
            }else if ([responseObject[@"code"] integerValue] == 400){
                    [self hideProgress];
                    [self showAlert:Localized(@"至少选择一个货币")];
            }
        }
        
    } faile:^(NSError *error) {
        if (error) {
            NSLog(@"%@",error);
        }
        
    }];
}
#pragma mark-当登陆后进入主界面获取所有钱包信息
-(void)getAllCoinsMessageForLogin{
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    NSArray *signArr = [FCLocalUserHelper getTimeAndSign];
    NSString *signStr = [NSString stringWithFormat:@"%@",signArr[1]];
    NSString *timeStr = [NSString stringWithFormat:@"%@",signArr[0]];
    [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
    [dict setObject:timeStr forKey:@"time"];
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    NSString *url = Get_load_wallets_URL;
    __weak __typeof(self)wself = self;
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        if (responseObject) {
            NSLog(@"%@",responseObject);
            if ([responseObject[@"code"] integerValue] == 200) {
                NSArray *arr = responseObject[@"result"];
                
                [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    FCWalletsModel *model = [FCWalletsModel mj_objectWithKeyValues:obj];
                    NSString *xidStr = [FCLocalUserHelper getXidStr];
                    model.XID = xidStr;
                    switch ([model.walletId integerValue]) {
                        case 1001:
                        {
                            model.iconImage = self.imageArr[0];
                            model.walletName = self.titleArr[0];
                        }
                            break;
                        case 1005:
                        {
                            model.iconImage = self.imageArr[1];
                            model.walletName = self.titleArr[1];
                        }
                            break;
                        case 1006:
                        {
                            model.iconImage = self.imageArr[2];
                            model.walletName = self.titleArr[2];
                        }
                            break;
                        case 1009:
                        {
                            model.iconImage = self.imageArr[3];
                            model.walletName = self.titleArr[3];
                        }
                            break;
                        case 1010:
                        {
                            model.iconImage = self.imageArr[4];
                            model.walletName = self.titleArr[4];
                        }
                            break;
                        default:
                            break;
                            
                            
                    }
                    
                    if ([model.choice isEqualToString:@"1"]) {
                        
                        if ([self.cchStatus isEqualToString:@"0"]) {
                           
                            if ([model.walletId isEqualToString:@"1001"]) {
                                self.walletModel2 = model;
                                [wself.loginAllCoinsArr addObject:self.walletModel2];
                            }
                            if ([model.walletId isEqualToString:@"1006"]) {
                                self.walletModel3 = model;
                                [wself.loginAllCoinsArr addObject:self.walletModel3];
                            }
                            if ([model.walletId isEqualToString:@"1005"]) {
                                self.walletModel4 = model;
                                [wself.loginAllCoinsArr addObject:self.walletModel4];
                            }
                            if ([model.walletId isEqualToString:@"1010"]) {
                                self.walletModel5 = model;
                                [wself.loginAllCoinsArr addObject:self.walletModel5];
                            }
                        }else{
                            if ([model.walletId isEqualToString:@"1009"]) {
                                self.walletModel1 = model;
                                [wself.loginAllCoinsArr addObject:self.walletModel1];
                                
                            }
                            if ([model.walletId isEqualToString:@"1001"]) {
                                self.walletModel2 = model;
                                [wself.loginAllCoinsArr addObject:self.walletModel2];
                            }
                            if ([model.walletId isEqualToString:@"1006"]) {
                                self.walletModel3 = model;
                                [wself.loginAllCoinsArr addObject:self.walletModel3];
                            }
                            if ([model.walletId isEqualToString:@"1005"]) {
                                self.walletModel4 = model;
                                [wself.loginAllCoinsArr addObject:self.walletModel4];
                            }
                            if ([model.walletId isEqualToString:@"1010"]) {
                                self.walletModel5 = model;
                                [wself.loginAllCoinsArr addObject:self.walletModel5];
                            }
                            
                        }
                        
                        
                    }
                }];
                
                wself.loginAllCoinsArr = [wself getAnArrayWithArray:wself.loginAllCoinsArr];
                wself.coinsArr = wself.loginAllCoinsArr;
                [wself reloadDatd];
                 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
                    
                    [wself getBalanceArr];
                });
                
            }
            
            
        }
        
    } faile:^(NSError *error) {
        if (error ) {
            NSLog(@"%@",error);
        }
        _bgNetView.hidden = NO;
        [self.tableView bringSubviewToFront:_bgNetView];
    }];
    
    
}
-(NSMutableArray *) getAnArrayWithArray:(NSMutableArray*)theArray
{
    NSMutableArray * mutableArray = [[NSMutableArray alloc]init];
    
    
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j<theArray.count; j++) {
            FCWalletsModel * modelj = theArray[j];
            if ([modelj.walletId isEqualToString:@"1009"] && i==0) {
                [mutableArray addObject:modelj];
                
            }
            if ([modelj.walletId isEqualToString:@"1001"] && i==1) {
                [mutableArray addObject:modelj];
            }
            if ([modelj.walletId isEqualToString:@"1006"] && i==2) {
                [mutableArray addObject:modelj];
            }
            if ([modelj.walletId isEqualToString:@"1005"] && i==3) {
                [mutableArray addObject:modelj];
            }
            if ([modelj.walletId isEqualToString:@"1010"] && i==4) {
                [mutableArray addObject:modelj];
            }
        }
    }
    return mutableArray;
}
#pragma mark-获取余额信息
-(void)getBalanceArr{
    __weak __typeof(self)wself = self;
    
        [self.coinsArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            FCWalletsModel *model = obj;
            
            [wself getBalanceWith:model.walletId];
        }];
}
-(void)getBalanceWith:(NSString*)walletId{
    __weak __typeof(self)wself = self;
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    NSArray *arrM =[FCLocalUserHelper getTimeAndSign];
    NSString *signStr = [NSString stringWithFormat:@"%@",arrM[1]];
    NSString *timeStr = [NSString stringWithFormat:@"%@",arrM[0]];
    [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
    [dict setObject:timeStr forKey:@"time"];
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    [dict setObject:walletId forKey:@"walletId"];
    NSString *url = Get_balance_URL;
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        
        if (responseObject) {
            NSLog(@"%@",responseObject);
            if ([responseObject[@"code"]integerValue] == 200) {
                
                _balanceModel = [FCBalanceModel mj_objectWithKeyValues:responseObject[@"result"]];
                NSString *xidStr = [FCLocalUserHelper getXidStr];
                _balanceModel.XID = xidStr;
                //获取每个货币的列表数据
                _balanceModel.walletId = walletId;
                [FCLocalUserHelper saveFMDBBalanceModelData:_balanceModel];
                //                    NSLog(@"walid%@",walletId);
                
                [wself.loginbalanceArr addObject:_balanceModel];
                
                
            }else if ([responseObject[@"code"] integerValue] == 404){
                [self hideProgress];
                [self showAlert:Localized(@"网络请求失败,请稍后再试!")];
            }
            wself.loginbalanceArr = [self getAnArrayWithArray:wself.loginbalanceArr];
            wself.balanceArr = wself.loginbalanceArr;
            
            [_pagerView reloadData];
            [self hideProgress];
            
            
           
        }
        
        
    } faile:^(NSError *error) {
        
        [self hideProgress];
        if (error) {
            NSLog(@"%@",error);
        }
        __weak __typeof(self)wself = self;
        [FCLocalUserHelper hasNetwork:^(bool has) {
            if (has)
            {
                [wself showAlert:Localized(@"网络请求失败")];
            } else
            {
                [wself showAlert:Localized(@"网络未连接")];
            }
        }];
        
    }];
    
    
    
}
#pragma mark-获取所有钱包信息
-(void)getAllCoinsMessage{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    NSArray *signArr = [FCLocalUserHelper getTimeAndSign];
    NSString *signStr = [NSString stringWithFormat:@"%@",signArr[1]];
    NSString *timeStr = [NSString stringWithFormat:@"%@",signArr[0]];
    [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
    [dict setObject:timeStr forKey:@"time"];
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    NSString *url = Get_load_wallets_URL;
    __weak __typeof(self)wself = self;
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        if (responseObject) {
            NSLog(@"%@",responseObject);
            if ([responseObject[@"code"] integerValue] == 200) {
                NSArray *arr = responseObject[@"result"];
                
                if (!kArrayIsEmpty(wself.coinsArr)) {
                    if (wself.coinsArr.count >0) {
                        [wself.coinsArr removeAllObjects];
                    }
                    
                }
                [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    FCWalletsModel *model = [FCWalletsModel mj_objectWithKeyValues:obj];
                    NSString *xidStr = [FCLocalUserHelper getXidStr];
                    model.XID = xidStr;
                    switch ([model.walletId integerValue]) {
                        case 1001:
                        {
                            model.iconImage = self.imageArr[0];
                            model.walletName = self.titleArr[0];
                        }
                            break;
                        case 1005:
                        {
                            model.iconImage = self.imageArr[1];
                            model.walletName = self.titleArr[1];
                        }
                            break;
                        case 1006:
                        {
                            model.iconImage = self.imageArr[2];
                            model.walletName = self.titleArr[2];
                        }
                            break;
                        case 1009:
                        {
                            model.iconImage = self.imageArr[3];
                            model.walletName = self.titleArr[3];
                        }
                            break;
                        case 1010:
                        {
                            model.iconImage = self.imageArr[4];
                            model.walletName = self.titleArr[4];
                        }
                            break;
                        default:
                            break;
                            
                            
                    }
                    if ([model.choice isEqualToString:@"1"]) {
                        
                        if ([self.cchStatus isEqualToString:@"0"]) {
                            
                            if ([model.walletId isEqualToString:@"1001"]) {
                                self.walletModelD2 = model;
                                [wself.deleteCoinsArr addObject:self.walletModelD2];
                            }
                            if ([model.walletId isEqualToString:@"1006"]) {
                                self.walletModelD3 = model;
                                [wself.deleteCoinsArr addObject:self.walletModelD3];
                            }
                            if ([model.walletId isEqualToString:@"1005"]) {
                                self.walletModelD4 = model;
                                [wself.deleteCoinsArr addObject:self.walletModelD4];
                            }
                            if ([model.walletId isEqualToString:@"1010"]) {
                                self.walletModelD5 = model;
                                [wself.deleteCoinsArr addObject:self.walletModelD5];
                            }
                            
                        }else{
                            if ([model.walletId isEqualToString:@"1009"]) {
                                self.walletModelD1 = model;
                                [wself.deleteCoinsArr addObject:self.walletModelD1];
                                
                            }
                            if ([model.walletId isEqualToString:@"1001"]) {
                                self.walletModelD2 = model;
                                [wself.deleteCoinsArr addObject:self.walletModelD2];
                            }
                            if ([model.walletId isEqualToString:@"1006"]) {
                                self.walletModelD3 = model;
                                [wself.deleteCoinsArr addObject:self.walletModelD3];
                            }
                            if ([model.walletId isEqualToString:@"1005"]) {
                                self.walletModelD4 = model;
                                [wself.deleteCoinsArr addObject:self.walletModelD4];
                            }
                            if ([model.walletId isEqualToString:@"1010"]) {
                                self.walletModelD5 = model;
                                [wself.deleteCoinsArr addObject:self.walletModelD5];
                            }
                        }
                        
                    }
                    
                }];
                wself.deleteCoinsArr = [wself getAnArrayWithArray:wself.deleteCoinsArr];
                wself.coinsArr = wself.deleteCoinsArr;
//                _pageControl.numberOfPages = self.coinsArr.count;
//                [_pagerView reloadData];
               
                [FCLocalUserHelper pushMainTabbarController];
                
            }
            
            
        }
        
    } faile:^(NSError *error) {
        if (error ) {
            NSLog(@"%@",error);
        }
        
    }];
    
    
    
}
#pragma mark-获取自己的信息
-(void)loadUserInfoData{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    
    if(!kStringIsEmpty([FCLocalUserHelper getXidStr]) && !kStringIsEmpty([FCLocalUserHelper getTokenStr])){
        NSMutableArray *arrM = [FCLocalUserHelper getTimeAndSign];
        NSString *signStr = [NSString stringWithFormat:@"%@",arrM[1]];
        NSString *timeStr = [NSString stringWithFormat:@"%@",arrM[0]];
        [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
        [dict setObject:timeStr forKey:@"time"];
    }
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    
    NSString *url = Get_my_information_URL;
    
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        if(responseObject){
            NSLog(@"%@",responseObject);
            NSDictionary *dic = responseObject;
            if([dic[@"code"] integerValue] == 200){
                FCUserModel *model = [FCUserModel mj_objectWithKeyValues:responseObject[@"result"]];
                NSString *xidStr = [FCLocalUserHelper getXidStr];
                model.XID = xidStr;
                [FCLocalUserHelper saveFMDBUserInfoData:model];
            }else if ([dic[@"code"] integerValue] == 405){
                
                [FCLocalUserHelper saveLoginStates:@"0"];
                //账号在其他设备登陆
                [self alertController];
            }
            
        }
        
    } faile:^(NSError *error) {
        
        if(error){
            NSLog(@"%@",error);
        }
        
    }];
    
}
-(void)alertController{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:Localized(@"提示") message:[NSString stringWithFormat:Localized(@"登录已失效，请重新登录")] preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:Localized(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        FCFirstVC *login = [FCFirstVC new];
        FCBaseNavigationVC *nvc = [[FCBaseNavigationVC alloc]init];
        nvc.viewControllers = @[login];
        /* 设置主控制器 */
        UIWindow *window = [[UIApplication sharedApplication] keyWindow];
        window.rootViewController = nvc;
        
    }]];
    [self presentViewController:alert animated:YES completion:nil];
}
#pragma mark-获取交易记录
-(void)postTransactionHistoryMessageWith:(NSString*)walletId{
    
    _bgTableViewView.hidden = YES;
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    NSArray *signArr = [FCLocalUserHelper getTimeAndSign];
    NSString *signStr = [NSString stringWithFormat:@"%@",signArr[1]];
    NSString *timeStr = [NSString stringWithFormat:@"%@",signArr[0]];
    [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
    [dict setObject:timeStr forKey:@"time"];
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    [dict setObject:walletId forKey:@"walletId"];
    [dict setObject:[NSString stringWithFormat:@"%zd",self.currentPage] forKey:@"page"];
    NSString *url = Get_wallet_histroy_URL;
    __weak __typeof(self)wself = self;
    
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        if (responseObject) {
            NSLog(@"%@",responseObject);
            if ([responseObject[@"code"] integerValue] == 200) {
               
                _transactionHistoryModel = [FCTransactionHistoryModel mj_objectWithKeyValues:responseObject[@"result"]];
                
               
                if (_transactionHistoryModel.orders.count>0) {
                  
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                        
                        NSArray *orderArr = _transactionHistoryModel.orders;
                        Language Language = [CLanguageUtil getCurrentLanguage];
                        //                        NSString * getTimeFormatIDStr = [FCLocalUserHelper getTimeFormatIDStr];
                        NSMutableArray *arrM = [NSMutableArray new];
                        [orderArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                            
                            FCTransactionHistoryDetailModel *detailModel = [FCTransactionHistoryDetailModel mj_objectWithKeyValues:obj];
                            NSString * sendTime = detailModel.sendTime;
                            switch (Language) {
                                case Language_Hans: case Language_Hant:
                                {
                                    detailModel.sendData = [FCLocalUserHelper changetimeIntervalChineseData:sendTime];
                                    
                                }
                                    break;
                                case Language_EN:
                                {
                                    detailModel.sendData = [FCLocalUserHelper changetimeIntervalData:sendTime];
                                }
                                    break;
                                default:
                                    break;
                            }
                            
                            [arrM addObject:detailModel];
                            [wself.orderArr addObject:detailModel];
                        }];
                        
                        if (self.currentPage ==1) {
                            wself.orderArr = arrM;
                        }else if(self.currentPage >1)
                        {
                            
                            for (int i =0 ; i<arrM.count; i++) {
                                FCTransactionHistoryDetailModel *model= arrM[i];
                                [wself.orderArr addObject:model];
                            }
                            
                        }
                        
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                        
                        [wself.tableView.mj_header endRefreshing];
                        [wself.tableView.mj_footer endRefreshing];
                        [self.tableView reloadData];
                        });
                        
                    });
                   
                    _bgTableViewView.hidden = YES;
                    
                }else{
                    
                    
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        [self.tableView reloadData];
                        [wself.tableView.mj_header endRefreshing];
                        [wself.tableView.mj_footer endRefreshing];
                    });

                     if ([responseObject[@"result"][@"nowpage"]  isEqual: @"1"] || [responseObject[@"result"][@"nowpage"]  isEqual: @"0"]) {
                             _refreshbtn.hidden = YES;
                             _bottomTipsLabel.hidden = NO;
                             _bottomTipsLabel.text = Localized(@"还没有数据");
                             [_bottomImageViewDismiss setImage:[UIImage imageNamed:@"img_data"]];
                             _bgTableViewView.hidden = NO;
                             [self.view bringSubviewToFront:_bgTableViewView];
                    
                     }
                }
            }
           
            
        }
        
    } faile:^(NSError *error) {
        if (error) {
            NSLog(@"%@",error);
        }
        _bottomImageViewDismiss.image= [UIImage imageNamed:@"img_network"];
        _bgTableViewView.hidden = NO;
        _bottomTipsLabel.hidden = YES;
        _refreshbtn.hidden = NO;
        [self.view bringSubviewToFront:_bgView];
       
        [wself.tableView.mj_header endRefreshing];
        [wself.tableView.mj_footer endRefreshing];
        wself.currentPage--;
    }];
    
    
}
#pragma mark-获取所有钱包地址
-(void)postAllWalletAddressWith:(NSString*)walletId{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
    NSArray *signArr = [FCLocalUserHelper getTimeAndSign];
    NSString *signStr = [NSString stringWithFormat:@"%@",signArr[1]];
    NSString *timeStr = [NSString stringWithFormat:@"%@",signArr[0]];
    [dict setObject:[FCLocalUserHelper sha1:signStr] forKey:@"sign"];
    [dict setObject:timeStr forKey:@"time"];
    [dict setObject:[FCLocalUserHelper getXidStr] forKey:@"XID"];
    [dict setObject:walletId forKey:@"walletId"];
    NSString *url = Get_new_address_URL;
    
    [FCSharedNetworkTool POSTWithURLString:url parameters:dict success:^(id responseObject) {
        if (responseObject) {
            NSLog(@"钱包地址信息:%@",responseObject);
            if ([responseObject[@"code"] integerValue]== 200) {
                
                FCAllAddressModel *addressModel = [FCAllAddressModel mj_objectWithKeyValues:responseObject[@"result"]];
                addressModel.XID = [FCLocalUserHelper getXidStr];
                //保存所有钱包地址
                [FCLocalUserHelper saveFMDBAllAddressModelData:addressModel];
            }
        }
        
    } faile:^(NSError *error) {
        if (error) {
            NSLog(@"%@",error);
        }
        
    }];
    
    
    
    
}
//刷新
- (void)refresh{
    
    
    
    __weak typeof(self) weakSelf = self;
    FCMJRefreshHeader *header = [FCMJRefreshHeader headerWithRefreshingBlock:^{
        
        weakSelf.currentPage = 1;
        
        NSString *walletId;
        if (weakSelf.walletIdStr == nil) {
            walletId = @"1009";
        }else{
            walletId = weakSelf.walletIdStr;
        }
        [weakSelf postTransactionHistoryMessageWith:walletId];
        
    }];
    
    weakSelf.tableView.mj_header = header;
    weakSelf.tableView.mj_footer = [FCMJRefreshFooter footerWithRefreshingBlock:^{
        weakSelf.currentPage++;
        NSString *walletId;
        if (weakSelf.walletIdStr == nil) {
            walletId = @"1009";
        }else{
            walletId = weakSelf.walletIdStr;
        }
        [weakSelf postTransactionHistoryMessageWith:walletId];
        
    }];
    
    
}

#pragma mark-懒加载
-(NSMutableArray *)orderArr{
    if (!_orderArr) {
        _orderArr = [NSMutableArray new];
    }
    return _orderArr;
}

-(NSMutableArray *)loginbalanceArr{
    if (!_loginbalanceArr) {
        _loginbalanceArr = [NSMutableArray new];
    }
    return _loginbalanceArr;
}
-(NSMutableArray *)loginAllCoinsArr{
    if (!_loginAllCoinsArr) {
        _loginAllCoinsArr = [NSMutableArray new];
    }
    return _loginAllCoinsArr;
}
-(NSMutableArray *)deleteCoinsArr{
    if (!_deleteCoinsArr) {
        _deleteCoinsArr = [NSMutableArray new];
    }
    return _deleteCoinsArr;
}

@end

